const app = getApp()
import {getAssetList} from "@/api/index"
Page({
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    assignedTo:wx.getStorageSync('id'),
    count:0,
    borrowing:0,
    fixing:0,
    returning:0
  },
  async getAssetCount(){
    const result=await getAssetList({assignedTo:this.data.assignedTo});
    console.log(result,7878)
    if(result.code==200){
      //获取资产总数
      const count = result.data.length
      //获取借用中资产数
      const borrowing = result.data.filter(item=>item.status==2).length
      //获取维修中资产数
      const fixing = result.data.filter(item=>item.status==3).length
      this.setData({
        count,
        borrowing,
        fixing
      })
    }else{
      wx.showToast({
        title: '获取数据失败',
        mask:true,
        icon:"error",
        duration:2000
      })
    }
   
    wx.stopPullDownRefresh()
  },
  onShow(){
    this.getAssetCount();
  },
  onPullDownRefresh(){
    this.getAssetCount();
  }
})
